import { message } from "antd";
import { useEffect, useRef, useState } from "react";
import { $eventBus, $EventBus_off, $EventBus_on, $export_excel } from "../../../../../../common/utils";
import { $Http } from "../../../../../../network";
import HomePage_TableComponent from "../../../../component/table";
import dayjs from 'dayjs';

// 主页-统计查询页面-主变数值分析页面
const HomePage_StatisticalQueryPage_MainTransformerNumericalAnalysisPage: React.FC = () => {
    const initParamsData = useRef<object>({})
    const paramsData = useRef<object>({})
    let [pageNo, setPageNo] = useState<number>(1)
    let [pageSize, setPageSize] = useState<number>(10)
    const [sourceData, setSourceData] = useState<object>({})
    const columnList = [
        {
            title: '序号',
            width: 60,
            render: (text: string, record: object, idx: number) => idx + 1,
        },
        {
            title: '站点',
            minWidth: 60,
            dataIndex: 'stationName',
            rowScope: 'row',
            render: (text: string) => text ?? "-"
        },
        {
            title: '主变',
            minWidth: 60,
            dataIndex: 'monitorMainName',
            render: (text: string) => text ?? "-"
        },
        {
            title: '类型',
            minWidth: 60,
            dataIndex: 'monitorDevice',
            render: (text: string) => text ?? "-"
        },
        {
            title: (<>
                <span>中性点直流</span>
                <br />
                <span>DC1(A)</span>
            </>),
            minWidth: 100,
            dataIndex: 'DC',
            align: "right",
            render: (text: string) => text ?? "-"
        },
        {
            title: (<>
                <span>中性点交流</span>
                <br />
                <span>AC(A)</span>
            </>),
            minWidth: 100,
            dataIndex: 'AC',
            align: "right",
            render: (text: string) => text ?? "-"
        },
        {
            title: (<>
                <span>噪声强度</span>
                <br />
                <span>NI(dB)</span>
            </>),
            minWidth: 85,
            dataIndex: 'NI',
            align: "right",
            render: (text: string) => text ?? "-"
        },
        {
            title: (<>
                <span>震动速度</span>
                <br />
                <span>VA(mm/s)</span>
            </>),
            minWidth: 85,
            dataIndex: 'VA',
            align: "right",
            render: (text: string) => text ?? "-"
        },
        {
            title: (<>
                <span>地表电位</span>
                <br />
                <span>EP1(V)</span>
            </>),
            minWidth: 85,
            dataIndex: 'EP',
            align: "right",
            render: (text: string) => text ?? "-"
        },
        {
            title: '更新时间',
            dataIndex: 'age',
            minWidth: 85,
            render: (text: string) => text ?? "-"
        },
    ];
    const http_search = () => {
        $Http("search", { typeName: "统计查询/主变数值分析", ...paramsData.current, pageNo, pageSize }).then((res) => {
            setSourceData({ ...res["data"] })
        })
    }


    const change_pagination = (no: number, size: number) => {
        pageNo = no
        pageSize = size
        setPageNo(pageNo)
        setPageSize(pageSize)
        http_search()
    }

    const change_export = (list: Array<number>) => {
        $export_excel("统计查询/主变数值分析", list)
    }

    // 广播函数数据
    const eventBusFuncData = {
        // 头部操作初始参数
        headerOperationInitParamsData: (data: object) => {


            initParamsData.current = data["data"]["initParamsData"]
            paramsData.current = data["data"]["initParamsData"]
            http_search()
        },
        // 头部操作查询
        headerOperationSearch: (data: object) => {
            pageNo = 1
            setPageNo(pageNo)
            paramsData.current = { ...paramsData.current, ...data["data"]["paramsData"] }
            http_search()
        },
        // 头部操作条件的开关
        headerOperationConditionSwitch: (data: object) => {
            pageNo = 1
            setPageNo(pageNo)
            paramsData.current = { ...initParamsData.current }
            http_search()
        },
    }



    useEffect(() => {
        $EventBus_on(eventBusFuncData)
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])
    return (
        <HomePage_TableComponent name="homePageStatisticalQueryPageMainTransformerNumericalAnalysisPageTable" isRowSelection columnList={columnList} pageNo={pageNo} pageSize={pageSize} sourceData={sourceData} change_pagination={change_pagination} change_selectedRowList={change_export} />
    )
}

export default HomePage_StatisticalQueryPage_MainTransformerNumericalAnalysisPage